package com.iwomy.envpro.platform.mapper;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iwomy.envpro.common.data.datascope.EnvproBaseMapper;
import com.iwomy.envpro.platform.VO.EquipmentGroupingStatisticsVO;
import com.iwomy.envpro.platform.VO.LargeScreenVO;
import com.iwomy.envpro.platform.entity.AirAbnormalEventEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LargeScreenMapper extends EnvproBaseMapper {
	@Select(" SELECT s.name AS `key`, COUNT(*) AS val " +
			" FROM  air_monitor_equipment AS e LEFT JOIN  air_site AS s " +
			" ON s.id = e.air_site_id" +
			" GROUP BY e.air_site_id  ORDER BY val DESC LIMIT 10")
	List<LargeScreenVO> equipmentGroupingStatistics();

	@Select("SELECT s.NAME AS `key`, COUNT(*) AS val  FROM air_site AS s" +
			" INNER JOIN alarm_logging AS l ON s.id = l.site_id " +
			" GROUP BY l.site_id ORDER BY val DESC  LIMIT 10")
	List<LargeScreenVO> groupAlarmStatistics();

//	@Select(" SELECT DATE(create_time) AS `key`, COUNT(*) AS val" +
//			" FROM alarm_logging" +
//			" WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL 1 WEEK)" +
//			" GROUP BY DATE(create_time)")
	
	@Select(" SELECT date_table.date AS `key`, COUNT(alarm_logging.id) AS val" +
			" FROM (" +
			" SELECT CURDATE() - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY AS date" +
			" FROM (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS a" +
			" CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS b" +
			" CROSS JOIN (SELECT 0 AS a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9) AS c" +
			" ) AS date_table" +
			" LEFT JOIN alarm_logging ON DATE(alarm_logging.create_time) = date_table.date" +
			" WHERE date_table.date >= CURDATE() - INTERVAL 1 WEEK" +
			" GROUP BY date_table.date" +
			" ORDER BY date_table.date;")
	List<LargeScreenVO> alarmTrendCurve();


}